﻿
using CSharpLibs.Annotations;

#pragma warning disable 0169

namespace System
{
	[Builtin]
	public struct Boolean : IUSignIntegralValue, IComparable, IComparable<Boolean>, IEquatable<Boolean>
	{
		[DummyPrimitiveField]
		private bool ff;

		[BuiltinMethod, BuiltinSemantics("bool_get_truth")]
		private static int GetTruthAsInt(Boolean b)
		{ return -1; }

		public int CompareTo(object o)
		{
			if(!(o is Boolean))
				Environment.Exit(1);

			return PrimitiveHelper.DoCompareOpIntegral(GetTruthAsInt(this), GetTruthAsInt((Boolean)o));
		}

		public int CompareTo(Boolean b)
		{ return PrimitiveHelper.DoCompareOpIntegral(GetTruthAsInt(this), GetTruthAsInt(b)); }

		public override bool Equals(object o)
		{ return (o is Boolean) && (GetTruthAsInt(this) == GetTruthAsInt((Boolean)o)); }

		public bool Equals(Boolean b)
		{ return this == b; }

		public override int GetHashCode()
		{ return (int)GetTruthAsInt(this); }

		public static bool Parse(String sv)
		{ return PrimitiveHelper.ParseIntegral(sv) == 0; }

		public  override string ToString()
		{ return PrimitiveHelper.IntegralToString(GetTruthAsInt(this)); }
	}
}

#pragma warning restore 0169

